import request from '@/utils/request'

// 获取所有用户
export function getAllUsers() {
    return request({
        url: '/users',
        method: 'get'
    })
}

// 搜索用户
export function searchUsers(params) {
    return request({
        url: '/users/search',
        method: 'get',
        params
    })
}

// 根据ID获取用户
export function getUserById(id) {
    return request({
        url: `/users/${id}`,
        method: 'get'
    })
}

// 根据ID获取用户及部门信息
export function getUserWithDeptById(id) {
    return request({
        url: `/users/${id}/with-dept`,
        method: 'get'
    })
}

// 添加用户
export function addUser(data) {
    return request({
        url: '/users',
        method: 'post',
        data
    })
}

// 更新用户
export function updateUser(id, data) {
    return request({
        url: `/users/${id}`,
        method: 'put',
        data
    })
}

// 删除用户
export function deleteUser(id) {
    return request({
        url: `/users/${id}`,
        method: 'delete'
    })
}

// 批量删除用户
export function batchDeleteUsers(ids) {
    return request({
        url: '/users/batch',
        method: 'delete',
        data: ids
    })
}

// 根据部门ID获取用户列表
export function getUsersByDepartmentId(departmentId) {
    return request({
        url: `/users/by-department/${departmentId}`,
        method: 'get'
    })
}

// 导入用户
export function importUsers(data) {
    return request({
        url: '/users/import',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

// 获取用户导入模板
export function getUserImportTemplate() {
    return request({
        url: '/users/import/template',
        method: 'get',
        responseType: 'blob'
    })
}

// 导出用户Excel
export function exportUsers() {
    return request({
        url: '/users/export',
        method: 'get',
        responseType: 'blob'
    })
} 